/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package itc.com.co.beans;

import BussinesLogic.PlanBL;
import EntidadesCM.PlanCM;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.event.FlowEvent;
import itc.com.co.beans.utils.SelectUtil;
import javax.faces.model.SelectItem;

/**
 *
 * @author Nas
 */
public class UserWizard {

    private String city;
    private String suburb;
    private Map<String, String> planes = new HashMap<String, String>();
    private Map<String, Map<String, String>> suburbsData = new HashMap<String, Map<String, String>>();
    private Map<String, String> suburbs = new HashMap<String, String>();

    public UserWizard() {
        List<SelectItem> listaPlanes;
        PlanBL planBL = new PlanBL();

        planes.put("Istanbul", "Istanbul");  
        planes.put("Ankara", "Ankara");  
        planes.put("Izmir", "Izmir");  

        Map<String, String> suburbsIstanbul = new HashMap<String, String>();
        suburbsIstanbul.put("Kadikoy", "Kadikoy");
        suburbsIstanbul.put("Levent", "Levent");
        suburbsIstanbul.put("Cengelkoy", "Cengelkoy");

        Map<String, String> suburbsAnkara = new HashMap<String, String>();
        suburbsAnkara.put("Kecioren", "Kecioren");
        suburbsAnkara.put("Cankaya", "Cankaya");
        suburbsAnkara.put("Yenimahalle", "Yenimahalle");

        Map<String, String> suburbsIzmir = new HashMap<String, String>();
        suburbsIzmir.put("Cesme", "Cesme");
        suburbsIzmir.put("Gumuldur", "Gumuldur");
        suburbsIzmir.put("Foca", "Foca");

        suburbsData.put("Istanbul", suburbsIstanbul);
        suburbsData.put("Ankara", suburbsAnkara);
        suburbsData.put("Izmir", suburbsIzmir);
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getSuburb() {
        return suburb;
    }

    public void setSuburb(String suburb) {
        this.suburb = suburb;
    }

    public Map<String, String> getCities() {
        return planes;
    }

    public void setCities(Map<String, String> planes) {
        this.planes = planes;
    }

    public Map<String, Map<String, String>> getSuburbsData() {
        return suburbsData;
    }

    public void setSuburbsData(Map<String, Map<String, String>> suburbsData) {
        this.suburbsData = suburbsData;
    }

    public Map<String, String> getSuburbs() {
        return suburbs;
    }

    public void setSuburbs(Map<String, String> suburbs) {
        this.suburbs = suburbs;
    }

    public void handleCityChange() {
        if (city != null && !city.equals("")) {
            suburbs = suburbsData.get(city);
        } else {
            suburbs = new HashMap<String, String>();
        }
    }

    public void displayLocation() {
        FacesMessage msg = new FacesMessage("Selected", "City:" + city + ", Suburb: " + suburb);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
    private User user = new User();
    private boolean skip;
    private static Logger logger = Logger.getLogger(UserWizard.class.getName());

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void save(ActionEvent actionEvent) {
        //Persist user

        FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getFirstname());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public boolean isSkip() {
        return skip;
    }

    public void setSkip(boolean skip) {
        this.skip = skip;
    }

    public String onFlowProcess(FlowEvent event) {
        logger.info("Current wizard step:" + event.getOldStep());
        logger.info("Next step:" + event.getNewStep());

        if (skip) {
            skip = false;	//reset in case user goes back
            return "confirm";
        } else {
            return event.getNewStep();
        }
    }
}
